home *** CD-ROM | disk | FTP | other *** search
- #!/sprite/cmds/csh -f
- #
- # A script to generate (or regenerate) a library directory Makefile
- # from a prototype Makefile. If ./Makefile.proto exists, use it, else
- # use a common prototype. This script is invoked for libraries that
- # have their sources distributed among a number of subdirectories; this
- # script is invoked in the subdirectories.
- #
- # We assume we were invoked from mkmf. Parameters passed in from mkmf
- # through environment variables:
- #
- # DOMACHINES names of machines we are supposed to run mkmf on
- # MKMFDIR directory containing prototype makefiles
- # MKMFFLAGS arguments to all mkmfs run recursively
- # MACHINES list of machine names (e.g. "sun2 sun3"), for
- # which there are machine-dependent subdirectories
- # (sun3.md, spur.md, etc.) of this directory.
- # MAKEFILE name of makefile to create
- # SUBTYPE information about what type of library this is:
- # used to figure out where to install things.
- #
-
- #
- # Argument processing. (Generalized form, even though just one flag so far.)
- #
- while ($#argv >= 1)
- if ("$1" == '-x') then
- set echo
- endif
- shift
- end
-
- set subtype=$SUBTYPE
- set lib=$cwd:h
- set lib=$lib:t
- set subdir=$cwd:t
- set pref='[a-z_A-Z]'
- set machines=($MACHINES)
- set domachines = ($DOMACHINES)
- set makefile=$MAKEFILE
- set distdir=($DISTDIR)
-
- if (-e $makefile.proto) then
- set proto=$makefile.proto
- else
- set proto="${MKMFDIR}/Makefile.biglib"
- endif
-
- echo "Generating $makefile for library subdirectory $lib/$cwd:t using $proto"
-
- set nonomatch
- set hdrs =( ${subdir}*.h )
- if ("$hdrs" == "${subdir}*.h") set hdrs=()
- set pubHdrs=(`echo $hdrs | sed -e "s/[^ ]*Int.h//g"`)
- set allSrcs =( ${pref}*.[cylsp] )
- #
- # Check to see if there were any sources. The first check (size == 1)
- # is only necessary because the second check will cause an error if
- # allSrcs contains more than 1024 bytes.
- #
- if ($#allSrcs == 1) then
- if ("$allSrcs" == "${pref}*.[cylsp]") set allSrcs=()
- endif
- set mdSrcs =( *.md/${pref}*.[cylsp] )
- if ($#mdSrcs == 1) then
- if ("$mdSrcs" == "*.md/${pref}*.[cylsp]") set mdSrcs=()
- endif
- set allSrcs=($allSrcs $mdSrcs)
- set lints = ( *.lint )
- if ("$lints" == "*.lint") set lints=()
- set manPages = (*.man)
- if ("$manPages" == "*.man") set manPages=()
-
- #
- # Use sed to substitute various interesting things into the prototype
- # makefile. The code below is a bit tricky because some of the variables
- # being substituted in can be very long: if the substitution is passed
- # to sed with "-e", the entire variable must fit in a single shell argument,
- # with a limit of 1024 characters. By generating a separate script file
- # for the very long variables, the variables get passed through (to the
- # script file) as many arguments, which gets around the length problem.
- #
-
- rm -f mkmf.tmp.sed
- echo s,"@(ALLSRCS)",$allSrcs,g > mkmf.tmp.sed
- echo s,"@(MANPAGES)",$manPages,g > mkmf.tmp.sed2
- cat $proto | sed -f mkmf.tmp.sed -f mkmf.tmp.sed2 \
- -e "s,@(DATE),`date`,g" \
- -e "s,@(LINTSRCS),$lints,g" \
- -e "s,@(MACHINES),$machines,g" \
- -e "s,@(MAKEFILE),$makefile,g" \
- -e "s,@(MANPAGES),$manPages,g" \
- -e "s,@(NAME),$lib,g" \
- -e "s,@(PUBHDRS),$pubHdrs,g" \
- -e "s,@(SUBDIR),$subdir,g" \
- -e "s,@(TEMPLATE),$proto,g" \
- -e "s,@(TYPE),$subtype,g" \
- -e "s,@(DISTDIR),$distdir,g" \
- > $makefile
- rm -f mkmf.tmp.sed mkmf.tmp.sed2
-
- setenv PARENTDIR $cwd
- foreach i ($domachines)
- (cd $i.md; mkmf $MKMFFLAGS -f md.mk)
- end
-